/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Util;

/**
 *
 * @author Jack
 */
import Database.ConnectToDatabase;
import java.sql.*;
import java.util.Vector;

public class DispatchNo {

    private int idproduce;
    private int idorder;
    private int iddispatch;
    private String namecustomer;

    /**
     * @return the idproduce
     */
    public int getIdproduce() {
        return idproduce;
    }

    /**
     * @param idproduce the idproduce to set
     */
    public void setIdproduce(int idproduce) {
        this.idproduce = idproduce;
    }

    /**
     * @return the quantity
     */
    public static Vector<DispatchNo> ListIDD() {
        Vector<DispatchNo> liste = new Vector<DispatchNo>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select order1.idcustomer,iddispatch,dispatchno.idorder,dispatchno.idproduce,namecustomer from dispatchno,order1,customer where order1.idcustomer=customer.idcustomer and dispatchno.idorder=order1.idorder  " + " order by iddispatch desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                DispatchNo em = new DispatchNo();
                em.setIddispatch(rs.getInt("iddispatch"));
                em.setIdproduce(rs.getInt("idproduce"));
                em.setIdorder(rs.getInt("idorder"));
                em.setNamecustomer(rs.getString("namecustomer"));

                liste.add(em);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<DispatchNo> ListIDDToDay(java.sql.Date today) {
        Vector<DispatchNo> liste = new Vector<DispatchNo>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select order1.idcustomer,iddispatch,dispatchno.idorder,dispatchno.idproduce,namecustomer from dispatchno,order1,customer where order1.idcustomer=customer.idcustomer and dispatchno.idorder=order1.idorder and order1.dateorder='" + today + "'" + " order by iddispatch desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                DispatchNo em = new DispatchNo();
                em.setIddispatch(rs.getInt("iddispatch"));
                em.setIdproduce(rs.getInt("idproduce"));
                em.setIdorder(rs.getInt("idorder"));
                em.setNamecustomer(rs.getString("namecustomer"));

                liste.add(em);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<DispatchNo> ListDispatchOnNameCustomer(String a) {
        Vector<DispatchNo> liste = new Vector<DispatchNo>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select order1.idcustomer,iddispatch,dispatchno.idorder,dispatchno.idproduce,namecustomer from dispatchno,order1,customer where order1.idcustomer=customer.idcustomer and dispatchno.idorder=order1.idorder and namecustomer like'%" + a + "%'" + " order by iddispatch desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                DispatchNo em = new DispatchNo();
                em.setIddispatch(rs.getInt("iddispatch"));
                em.setIdproduce(rs.getInt("idproduce"));
                em.setIdorder(rs.getInt("idorder"));
                em.setNamecustomer(rs.getString("namecustomer"));

                liste.add(em);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<DispatchNo> ListDispatchOnIDCustomer(int a) {
        Vector<DispatchNo> liste = new Vector<DispatchNo>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select order1.idcustomer,iddispatch,dispatchno.idorder,dispatchno.idproduce,namecustomer from dispatchno,order1,customer where order1.idcustomer=customer.idcustomer and dispatchno.idorder=order1.idorder and customer.idcustomer=" + a + " order by iddispatch desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                DispatchNo em = new DispatchNo();
                em.setIddispatch(rs.getInt("iddispatch"));
                em.setIdproduce(rs.getInt("idproduce"));
                em.setIdorder(rs.getInt("idorder"));
                em.setNamecustomer(rs.getString("namecustomer"));

                liste.add(em);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<DispatchNo> ListIDDONID(int a) {
        Vector<DispatchNo> liste = new Vector<DispatchNo>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select order1.idcustomer,iddispatch,dispatchno.idorder,dispatchno.idproduce,namecustomer from dispatchno,order1,customer where order1.idcustomer=customer.idcustomer and dispatchno.idorder=order1.idorder and dispatchno.iddispatch= " + a + " order by iddispatch desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                DispatchNo em = new DispatchNo();
                em.setIddispatch(rs.getInt("iddispatch"));
                em.setIdproduce(rs.getInt("idproduce"));
                em.setIdorder(rs.getInt("idorder"));
                em.setNamecustomer(rs.getString("namecustomer"));

                liste.add(em);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public static Vector<DispatchNo> ListIDDONOD(int a) {
        Vector<DispatchNo> liste = new Vector<DispatchNo>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select order1.idcustomer,iddispatch,dispatchno.idorder,dispatchno.idproduce,namecustomer from dispatchno,order1,customer where order1.idcustomer=customer.idcustomer and dispatchno.idorder=order1.idorder and dispatchno.idorder= " + a + " order by iddispatch desc";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                DispatchNo em = new DispatchNo();
                em.setIddispatch(rs.getInt("iddispatch"));
                em.setIdproduce(rs.getInt("idproduce"));
                em.setIdorder(rs.getInt("idorder"));
                em.setNamecustomer(rs.getString("namecustomer"));

                liste.add(em);
            }
        } catch (Exception ex) {
            liste = null;
        }
        return liste;
    }

    public boolean adddispatch() {

        return CommonQuery.Command("insert into dispatchno values(" + this.idproduce + "," + this.idorder + ")");
    }

    public boolean updateproduce() {

        return CommonQuery.Command("update dispatchno set idproduce=" + this.idproduce + " where iddispatch= " + this.iddispatch);
    }

    public boolean deletedispatch() {
        return CommonQuery.Command("delete dispatchno where iddispatch=" + this.iddispatch);
    }

    public static float ListMoney(int a) {
        float liste = 0;
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select price from dispatchno,produce where dispatchno.idproduce=produce.idproduce and dispatchno.idorder= " + a;
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {


                liste += rs.getFloat("price");
            }
        } catch (Exception ex) {
            liste = 0;
        }
        return liste;
    }

    /**
     * @return the iddispatch
     */
    public int getIddispatch() {
        return iddispatch;
    }

    /**
     * @param iddispatch the iddispatch to set
     */
    public void setIddispatch(int iddispatch) {
        this.iddispatch = iddispatch;
    }

    /**
     * @return the iporder
     */
    public int getIdorder() {
        return idorder;
    }

    /**
     * @param iporder the iporder to set
     */
    public void setIdorder(int idorder) {
        this.idorder = idorder;
    }

    /**
     * @return the namecustomer
     */
    public String getNamecustomer() {
        return namecustomer;
    }

    /**
     * @param namecustomer the namecustomer to set
     */
    public void setNamecustomer(String namecustomer) {
        this.namecustomer = namecustomer;
    }
    /**
     * @return the idcustomer
     */
}
